package com.v2future.sjt.collegecheckingattendance.leave;

import android.content.Intent;
import android.view.View;

import com.v2future.sjt.collegecheckingattendance.MainActivity;
import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.utils.BaseResponseBean;
import com.v2future.sjt.collegecheckingattendance.utils.CalculateTime;
import com.v2future.sjt.collegecheckingattendance.utils.Constants;
import com.v2future.sjt.collegecheckingattendance.utils.DateUtil;
import com.v2future.sjt.collegecheckingattendance.utils.IntentKey;
import com.v2future.sjt.collegecheckingattendance.utils.StringUtil;
import com.v2future.sjt.collegecheckingattendance.utils.netutils.BaseRequestParams;
import com.v2future.sjt.collegecheckingattendance.utils.netutils.NetTaskListener;
import com.v2future.sjt.collegecheckingattendance.utils.netutils.NetUtils;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

import cn.aigestudio.datepicker.cons.DPMode;
import cn.aigestudio.datepicker.views.DatePicker;

/**
 * 外出假选择日期
 *
 * @author shijianting
 * @time 2016/3/30 11:02
 */
public class OutLeaveDatePickerActivity extends MainActivity {

    DatePicker dp;

    private List<String> selectDates;

    /**
     * 标识：选中日期
     * 格式2016-2-11
     */
    public static final String TAG_SELECT_DATE = "selectDate";

    @Override
    public void init() {

    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_date_selector);
        setTitleText("外出假日期");
        initTitleBack(null);
        dp = (DatePicker) findViewById(R.id.main_dp);
    }

    @Override
    public void initAfter() {
        int month = Integer.parseInt(DateUtil.getCurrentDateMonth());//获取当前月份
        dp.setDate(2016, month);
        dp.setTodayDisplay(true);
        dp.setMode(DPMode.MULTIPLE);
        dp.setOnDateSelectedListener(new DatePicker.OnDateSelectedListener() {
            @Override
            public void onDateSelected(List<String> date) {
                selectDates = date;
                submitLeaveListener.onClick(null);
            }
        });
    }

    /**
     * 检查日期是否正确
     * @return
     */
    private boolean checkDates(){
        for (String date:selectDates) {
            if (CalculateTime.compare_date(date, DateUtil.getCurrentDateYMD()) > 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * 请假事件
     */
    View.OnClickListener submitLeaveListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!checkDates()) {
                showSimpleDialog("不能请过去的假哦~");
                return;
            }
            Intent intent = new Intent(OutLeaveDatePickerActivity.this, OutLeaveFillinInfoActivity.class);
            intent.putExtra(TAG_SELECT_DATE, (Serializable) selectDates);
            startActivity(intent);
        }
    };
}
